package opreation.impl;

import book.Book;
import book.BookList;
import opreation.IOperation;

//更新书籍的信息
public class UpdateOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.print("请输入要更新的书籍：");
        String name = scanner.next();
        if(bookList.contains(name)){
            Book book = bookList.findBook(name);
            System.out.println("该书籍信息如下：");
            System.out.println(book);
            int choice = 0;
            while(choice != -1){
                System.out.println("请输入需要更新的信息：");
                System.out.println("1.价格 2.类型 3.借阅状态 4.全部 -1.退出");
                choice = scanner.nextInt();
                switch(choice){
                    case 4:
                    case 1:
                        System.out.print("请输入要修改的价格：");
                        book.setPrice(scanner.nextDouble());
                        if(choice != 4)
                            break;
                    case 2:
                        System.out.print("请输入要修改的类型：");
                        book.setType(scanner.next());
                        if(choice != 4)
                            break;
                    case 3:
                        System.out.print("请输入要修改的借阅状态：");
                        String isBorrowed = scanner.next();
                        if("否".equals(isBorrowed)){
                            book.setBorrowed(false);
                        }else{
                            book.setBorrowed(true);
                        }
                        if(choice != 4)
                            break;
                    default:
                        break;
                }
                if(choice != -1)
                System.out.println("修改成功！");
            }
        }else{
            System.out.println("您要删除的书籍不存在！");
        }
    }
}
